import {
  addAttendGroup,
  addRuleHoliday,
  addRuleMakeup,
  addRuleOvertimeList,
  addRuleServiceTime,
  delAttendGroupInfo,
  delRuleHoliday,
  delRuleMakeup,
  delRuleOvertime,
  delRuleServiceTime,
  getAattendGroupLils,
  getAtteConfig,
  getAttendanceDetails,
  getAttendanceList,
  getAttendGroupInfo,
  getRuleHolidayList,
  getRuleMakeupList,
  getRuleOvertimeInfo,
  getRuleOvertimeList,
  putAtteConfig,
  putAttendGroupInfo,
  putRuleHoliday,
  putRuleOvertimeList,
  putRuleServiceTime,
  signExoprt
} from '@/api/attendance'

const state = {
  attendanceList: {},
}

const mutations = {
  SET_ATTENDANCELIST: (state, data) => {
    state.attendanceList = data
  }
}

const actions = {
  // 获取考勤设置
  getAtteConfigAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getAtteConfig(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 保存考勤设置
  putAtteConfigAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      putAtteConfig(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取考勤列表
  attendanceList({ commit }, params) {
    return new Promise((resolve, reject) => {
      getAttendanceList(params).then(response => {
        const { data } = response
        commit('SET_ATTENDANCELIST', data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取考勤详情
  attendanceDetails({ commit }, params) {
    return new Promise((resolve, reject) => {
      getAttendanceDetails(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取考勤组列表
  getAattendGroupLilsAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getAattendGroupLils(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 添加考勤组
  addAttendGroupAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      addAttendGroup(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取考勤组信息
  getAttendGroupInfoAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getAttendGroupInfo(params).then(response => {
        const { data } = response
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 更新考勤组信息
  putAttendGroupInfoAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      putAttendGroupInfo(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 删除考勤组
  delAttendGroupInfoAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      delAttendGroupInfo(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 加班规则列表
  getRuleOvertimeListAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getRuleOvertimeList(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 添加加班规则
  addRuleOvertimeListAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      addRuleOvertimeList(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 更新加班规则
  putRuleOvertimeListAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      putRuleOvertimeList(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 获取加班规则信息
  getRuleOvertimeInfoAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getRuleOvertimeInfo(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 删除加班规则
  delRuleOvertimeAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      delRuleOvertime(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 补卡规则列表
  getRuleMakeupListAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getRuleMakeupList(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 更新补卡规则
  addRuleMakeupAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      addRuleMakeup(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 删除补卡规则
  delRuleMakeupAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      delRuleMakeup(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 假期规则列表
  getRuleHolidayListAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      getRuleHolidayList(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 添加假期规则
  addRuleHolidayAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      addRuleHoliday(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 更新假期规则
  putRuleHolidayAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      putRuleHoliday(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 删除假期规则
  delRuleHolidayAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      delRuleHoliday(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 添加假期司龄规则
  addRuleServiceTimeAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      addRuleServiceTime(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 更新假期司龄规则
  putRuleServiceTimeAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      putRuleServiceTime(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 删除假期司龄规则
  delRuleServiceTimeAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      delRuleServiceTime(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 导出数据
  signExoprtAct({ commit }, params) {
    return new Promise((resolve, reject) => {
      signExoprt(params).then(response => {
        const data = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

